Skip to content

api: DownOptions.Images becomes a typed ImagePruneMode, validated upfront - #14149

Merged
glours merged 3 commits into
docker:mainfrom
ndeloof:b6-image-prune-mode
Oct 6, 2026
Merged

glours merged 3 commits into
docker:mainfrom
ndeloof:b6-image-prune-mode

Conversation

@ndeloof

@ndeloof ndeloof commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Epic #14074, B.6. The legal values of DownOptions.Images lived in pkg/compose while the field was a bare string in pkg/api, and the only validation fired inside ImagesToPrune — after down had already removed the project's containers, leaving the teardown half done on a typo (SDK callers only; the CLI validated its --rmi flag separately).

  • ImagePruneMode and its three values move to pkg/api, next to the field they constrain (type-aliased in pkg/compose for existing consumers — untyped string literals still compile);
  • down() rejects any other value before touching a single resource;
  • the CLI --rmi check reuses the same definition;
  • a unit test runs Down with expectation-free mocks: one daemon call would fail it. Mocks verified in sync (make mocks, no drift).

🤖 Generated with Claude Code

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/compose/down.go 33.33% 1 Missing and 1 partial ⚠️
pkg/api/api.go 66.66% 2 Missing ⚠️
pkg/compose/image_pruner.go 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@ndeloof
ndeloof force-pushed the b6-image-prune-mode branch from 6167efd to 652b348 Compare September 15, 2026 12:58

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something we need to check before we merge IMHO

Comment thread pkg/compose/image_pruner.go
…ront

The legal values of DownOptions.Images lived in pkg/compose
(image_pruner.go) while the field itself was a bare string in pkg/api,
and the only validation fired inside ImagesToPrune — after down had
already removed the project's containers, leaving the teardown half
done on a typo. The CLI validated its --rmi flag separately, so only
SDK callers were exposed.

ImagePruneMode and its three values now live in pkg/api next to the
field they constrain (type-aliased in pkg/compose for existing
consumers), down() rejects any other value before touching a single
resource, and the CLI check reuses the same definition. A unit test
runs Down with expectation-free mocks: one daemon call would fail it.

Epic docker#14074, B.6.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof force-pushed the b6-image-prune-mode branch from 652b348 to 31549ed Compare October 6, 2026 08:35
ImagesToPrune's own check duplicated the same set of legal
ImagePruneMode values down() already validates upfront, risking silent
drift if a mode is ever added. Reuse Valid() instead.

Suggested-by: glours docker#14149 (comment)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
down() validates options.Images upfront, but ImagePruner is exported
and can be driven directly with a hand-built ImagePruneOptions that
bypasses that check. Add a direct test for the Valid() guard added in
the previous commit, so the two checks can't silently drift without a
test catching it.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested a review from docker-agent October 6, 2026 09:11

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours
glours merged commit aab5848 into docker:main Oct 6, 2026
63 checks passed
glours pushed a commit that referenced this pull request Oct 6, 2026
ImagesToPrune's own check duplicated the same set of legal
ImagePruneMode values down() already validates upfront, risking silent
drift if a mode is ever added. Reuse Valid() instead.

Suggested-by: glours #14149 (comment)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants